/**
 * clock.c
 *
 * A GTK+ widget that implements a clock face
 *
 * (c) 2005, Davyd Madeley
 *
 * Authors:
 *   Davyd Madeley  <davyd@madeley.id.au>
 */

#include <gtk/gtk.h>
#include <math.h>

#include "clock.h"

G_DEFINE_TYPE (EggClockFace, egg_clock_face, GTK_TYPE_DRAWING_AREA);

static gboolean egg_clock_face_expose (GtkWidget *clock, GdkEventExpose *event);

static void
egg_clock_face_class_init (EggClockFaceClass *class)
{
	GtkWidgetClass *widget_class;

	widget_class = GTK_WIDGET_CLASS (class);

	widget_class->expose_event = egg_clock_face_expose;
}

static void
egg_clock_face_init (EggClockFace *clock)
{
}

static void
draw (GtkWidget *clock, cairo_t *cr)
{
	double x, y, xx, yy, X;
	double radius;
	int i,j,c;
	
	xx = clock->allocation.width;
	yy = clock->allocation.height;
	x = clock->allocation.x + clock->allocation.width / 2; 
 	y = clock->allocation.y + clock->allocation.height / 2;
 	radius = MIN (clock->allocation.width / 2, 
 		      clock->allocation.height / 2) - 5; 

	if ( xx > yy ){
		X=1*yy/800;
	} else {
		X=1*xx/800;
	}

	printf("%f\n",X);
	cairo_set_source_rgb (cr, 0, 0, 0);
	cairo_move_to(cr,688.02380*X,753.51590*X);
	cairo_line_to(cr,688.02380*X,627.51590*X); 
	cairo_curve_to(cr,688.02380*X,582.51590*X, 661.62380*X,455.01590*X, 553.02380*X,411.51590*X);
	cairo_curve_to(cr,598.02380*X,357.51590*X, 607.02380*X,258.51590*X, 517.02380*X,195.51590*X);
	cairo_curve_to(cr,544.02380*X,159.51590*X, 517.02380*X,33.515900*X, 409.02380*X,33.515900*X);
	cairo_curve_to(cr,301.02380*X,33.515900*X, 274.02380*X,159.51590*X, 301.02380*X,195.51590*X);
	cairo_curve_to(cr,211.02380*X,258.51590*X, 220.02380*X,357.51590*X, 265.02380*X,411.51590*X);
	cairo_curve_to(cr,157.02380*X,456.51590*X, 130.02380*X,582.51590*X, 130.02380*X,627.51590*X);
	cairo_line_to(cr,130.02380*X,753.51590*X);
	cairo_line_to(cr,688.02380*X,753.51590*X);
	cairo_stroke(cr);
	cairo_move_to(cr,409.02380*X,87.515900*X);
	cairo_curve_to(cr,490.02380*X,87.515900*X, 490.02380*X,177.51590*X, 454.02380*X,213.51590*X);
	cairo_curve_to(cr,562.02380*X,258.51590*X, 535.02380*X,375.51590*X, 481.02380*X,429.51590*X);
	cairo_curve_to(cr,571.02380*X,456.51590*X, 634.02380*X,546.51590*X, 634.02380*X,609.51590*X);
	cairo_line_to(cr,634.02380*X,699.51590*X);
	cairo_line_to(cr,184.02380*X,699.51590*X);
	cairo_line_to(cr,184.02380*X,609.51590*X);
	cairo_curve_to(cr,184.02380*X,546.51590*X, 247.02380*X,456.51590*X, 337.02380*X,429.51590*X);
	cairo_curve_to(cr,283.02380*X,375.51590*X, 256.02380*X,258.51590*X, 364.02380*X,213.51590*X);
	cairo_curve_to(cr,328.02380*X,177.51590*X, 328.02380*X,87.515900*X, 409.02380*X,87.515900*X);
	cairo_stroke(cr);
	cairo_restore (cr);/*  stack-pen-size */

       
static gboolean
egg_clock_face_expose (GtkWidget *clock, GdkEventExpose *event)
{
	cairo_t *cr;

	/* get a cairo_t */
	cr = gdk_cairo_create (clock->window);

	cairo_rectangle (cr,
			event->area.x, event->area.y,
			event->area.width, event->area.height);
	cairo_clip (cr);
	
	draw (clock, cr);

	cairo_destroy (cr);

	return FALSE;
}

GtkWidget *
egg_clock_face_new (void)
{
	return g_object_new (EGG_TYPE_CLOCK_FACE, NULL);
}
